<?php

/**
 * 系统辅助类
 */

namespace Services;

use Symfony\Component\DependencyInjection\ContainerInterface;

class Systems
{
    private $request;

    public function __construct(ContainerInterface $container)
    {
        $this->request = $container->get('request');
    }

    /**
    * Detect if the server is running Windows
    *
    * @return bool
    */
    public function isWindows()
    {
        return strncasecmp(PHP_OS, 'WIN', 3) == 0;
    }
    /**
    * Detect if the server is running on Mac
    * @return bool
    */
    public function isMac()
    {
        return strncasecmp(PHP_OS, 'Darwin', 6) == 0;
    }
    
    /**
     * 获取系统
     *
     * @return string
     */
    public function getOS()
    {
        $agent = strtolower($this->request->server->get('HTTP_USER_AGENT'));
        if (strpos($agent, 'micromessenger')) {
            $platform = 'weixin';
        } elseif (strpos($agent, 'windows nt')) {
            $platform = 'windows';
        } elseif (strpos($agent, 'macintosh')) {
            $platform = 'mac';
        } elseif (strpos($agent, 'ipod')) {
            $platform = 'ipod';
        } elseif (strpos($agent, 'ipad')) {
            $platform = 'ipad';
        } elseif (strpos($agent, 'iphone')) {
            $platform = 'iphone';
        } elseif (strpos($agent, 'android')) {
            $platform = 'android';
        } elseif (strpos($agent, 'unix')) {
            $platform = 'unix';
        } elseif (strpos($agent, 'linux')) {
            $platform = 'linux';
        } else {
            $platform = 'other';
        }
        
        return $platform;
    }
    
    /**
     * 判断是否微信浏览器
     * 
     * @return boolean
     */
    public function isWeixin()
    {
        return ($this->getOS() === 'weixin') ? true : false;
    }    
    
}